<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
 * S7Ncms - www.s7n.de
 *
 * Copyright (c) 2007-2009, Eduard Baun <eduard at baun.de>
 * All rights reserved.
 *
 * See license.txt for full text and disclaimer
 *
 * @author Eduard Baun <eduard at baun.de>
 * @copyright Eduard Baun, 2007-2009
 * @version $Id$
 */

class Module_Model extends ORM {


	public function installed()
	{
		return $this;
	}

	public function enabled($name = NULL)
	{
		if ($name === NULL)
			return $this->where('enabled', TRUE);
		else
			return (bool) $this->db
				->select('id')
				->where(array('name' => $name, 'enabled' => TRUE))
				->count_records('config_languages');
	}

	public function unique_key($id)
	{
		if ( ! empty($id) AND is_string($id) AND ! ctype_digit($id))
		{
			return 'name';
		}

		return parent::unique_key($id);
	}

}